unit birdenfazla;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ExtCtrls, ppDB, ppDBPipe, ppCtrls, ppBands, ppVar, ppPrnabl, ppClass,
  ppCache, ppComm, ppRelatv, ppProd, ppReport, StdCtrls, Buttons, Grids,
  Wwdbigrd, Wwdbgrid, wwdblook, Db, ADODB, wwdbdatetimepicker,
  ppViewr, TXComp, TXRB, siComp;

type
  Tbirdenfazlaf = class(TForm)
    Label15: TLabel;
    Label14: TLabel;
    BitTar: TwwDBDateTimePicker;
    basTar: TwwDBDateTimePicker;
    Tekniktipi: TADOQuery;
    TekniktipiS: TDataSource;
    CheckBox2: TCheckBox;
    tipi: TwwDBLookupCombo;
    wwDBGrid1: TwwDBGrid;
    Panel2: TPanel;
    pKapat: TPanel;
    BitBtn5: TBitBtn;
    BitBtn1: TBitBtn;
    bYazdir: TBitBtn;
    qTekLstS: TDataSource;
    qTekLst: TADOQuery;
    pptekrapor: TppReport;
    ppDBPipeline1: TppDBPipeline;
    Bevel1: TBevel;
    Label1: TLabel;
    ppHeaderBand1: TppHeaderBand;
    ppDetailBand1: TppDetailBand;
    ppFooterBand1: TppFooterBand;
    ppTitleBand1: TppTitleBand;
    ppLabel1: TppLabel;
    ppSystemVariable1: TppSystemVariable;
    ppSystemVariable2: TppSystemVariable;
    ppDBText1: TppDBText;
    ppLabel2: TppLabel;
    ppDBText2: TppDBText;
    ppLabel3: TppLabel;
    ppLine1: TppLine;
    ppLine2: TppLine;
    ppLabel4: TppLabel;
    ppLabel5: TppLabel;
    d1: TppLabel;
    d2: TppLabel;
    ppLabel8: TppLabel;
    d3: TppLabel;
    Memo1: TMemo;
    ExtraOptions1: TExtraOptions;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormShow(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure CheckBox2Click(Sender: TObject);
    procedure bYazdirClick(Sender: TObject);
    procedure pptekraporPreviewFormCreate(Sender: TObject);
  private
    { Private declarations }
    procedure CreateParams(var Params: TCreateParams); override;
  public
    { Public declarations }
  end;

var
  birdenfazlaf: Tbirdenfazlaf;

implementation

uses ana1;

{$R *.DFM}

procedure Tbirdenfazlaf.CreateParams(var Params: TCreateParams);
begin
  inherited CreateParams(Params);
  Params.WndParent := GetDesktopWindow;
end;

procedure Tbirdenfazlaf.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  action := cafree;
  birdenfazlaf := nil;

end;

procedure Tbirdenfazlaf.FormShow(Sender: TObject);
begin
  Tekniktipi.close;
  Tekniktipi.open;

end;

procedure Tbirdenfazlaf.BitBtn1Click(Sender: TObject);
var
  toplam: integer;
begin
  qTekLst.Close;
  qTekLst.SQL.Clear;
  qTekLst.SQL.Add('select onarim.serino,max(onarim.stokkod) as stokkod,count(onarim.serino) as adet into #yeni1 from teknik,onarim');
  qTekLst.SQL.Add('where (onarim.formno=teknik.formno)');
  qTekLst.SQL.Add('and (teknik.tarih>:bastar) and (teknik.tarih<:bittar)');

  if CheckBox2.Checked then
    qTekLst.SQL.Add('and (teknik.Tipi=''' + Tipi.LookupValue + ''')');

  qTekLst.SQL.Add('group by onarim.serino');
  qTekLst.SQL.Add('having count(onarim.serino)>1');

  qTekLst.SQL.Add('select stokkod,stokkodu=(select top 1 stokkodu from stok where stok.stokkod=#yeni1.stokkod),sum(adet) as adet from #yeni1');
  qTekLst.SQL.Add('group by stokkod');
  qTekLst.SQL.Add('order by adet desc');

  qTekLst.Parameters.ParamByName('BasTar').datatype := ftDate;
  qTekLst.Parameters.ParamByName('BitTar').datatype := ftDate;
  qTekLst.Parameters.ParamByName('BasTar').value := BasTar.date;
  qTekLst.Parameters.ParamByName('BitTar').value := BitTar.date + 1;

  memo1.Lines := qteklst.sql;
  qTekLst.Open;

  qTekLst.first;
  qTekLst.DisableControls;
  toplam := 0;
  while not qTekLst.eof do
  begin
    toplam := toplam + qTekLst.fieldbyname('adet').asinteger;
    qTekLst.next;
  end;

  qTekLst.enableControls;

  Label1.Caption := '(Toplam :' + inttostr(toplam) + ')';
  wwDBGrid1.SetFocus;

end;

procedure Tbirdenfazlaf.CheckBox2Click(Sender: TObject);
begin
  if CheckBox2.Checked then
  begin
    Tipi.Enabled := true;
    Tipi.SetFocus;
  end
  else
  begin
    tipi.value := '';
    Tipi.Enabled := False;
  end;

end;

procedure Tbirdenfazlaf.bYazdirClick(Sender: TObject);
begin
  d1.Caption := bastar.Text;
  d2.Caption := bittar.Text;
  d3.Caption := tipi.text;

  pptekrapor.print;

end;

procedure Tbirdenfazlaf.pptekraporPreviewFormCreate(Sender: TObject);
begin
  pptekrapor.PreviewForm.WindowState := wsMaximized;
  //  TppViewer(pptekrapor.PreviewForm.Viewer).ZoomSetting := zs100Percent;

end;

end.
